Skip to content

Conversation

cetagostini
Copy link
Contributor

@cetagostini cetagostini commented Oct 8, 2025

Description

Added a new notebook 'mmm_gam_options.ipynb' demonstrating custom Bayesian GAMs with PyMC-Marketing. Updated the gallery to include a link to this new example.

Related Issue

  • Closes #
  • Related to #

Checklist


📚 Documentation preview 📚: https://pymc-marketing--1985.org.readthedocs.build/en/1985/

Added a new notebook 'mmm_gam_options.ipynb' demonstrating custom Bayesian GAMs with PyMC-Marketing. Updated the gallery to include a link to this new example.
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions github-actions bot added docs Improvements or additions to documentation MMM labels Oct 8, 2025
@cetagostini cetagostini changed the title Cetagostini/showing gam capabilities from pymc marketing Notebook: PyMC-Marketing GAM capabilities Oct 8, 2025
Copy link

review-notebook-app bot commented Oct 8, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-10-08T11:36:22Z
----------------------------------------------------------------

Line #1.    seed: int = sum(map(ord, "pymc-marketing is more than just a marketing model"))

This can be on the "setting the notebook section"


Copy link

review-notebook-app bot commented Oct 8, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-10-08T11:36:23Z
----------------------------------------------------------------

Provide some storytelling on what type of series and how many we plan to generate, and what's the objective.


cetagostini commented on 2025-10-08T16:42:36Z
----------------------------------------------------------------

Added above in the data generation process title.

Copy link

review-notebook-app bot commented Oct 8, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-10-08T11:36:23Z
----------------------------------------------------------------

Line #1.    countries = ["Venezuela", "Colombia", "Ecuardo", "Panama"]

Typo "Ecuador"


cetagostini commented on 2025-10-08T16:43:14Z
----------------------------------------------------------------

Done!

Copy link

review-notebook-app bot commented Oct 8, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-10-08T11:36:24Z
----------------------------------------------------------------

super title overlaps with some subtitles


cetagostini commented on 2025-10-08T16:46:15Z
----------------------------------------------------------------

Done!

Copy link

review-notebook-app bot commented Oct 8, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-10-08T11:36:25Z
----------------------------------------------------------------

Line #19.                & (multi_country_df["product_type"] == product_type)

Tip: using strings with query can look more readable https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html


Copy link

review-notebook-app bot commented Oct 8, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-10-08T11:36:25Z
----------------------------------------------------------------

Same here for the titles


Copy link

review-notebook-app bot commented Oct 8, 2025

View / edit / reply to this conversation on ReviewNB

juanitorduz commented on 2025-10-08T11:36:26Z
----------------------------------------------------------------

Add a subsection "multidimensional model" just to separate sections better?


cetagostini commented on 2025-10-08T16:47:43Z
----------------------------------------------------------------

Done!

@juanitorduz
Copy link
Collaborator

This notebook is fantastic @cetagostini ! 🚀 ! I left some minor comments.

Overall, I suggest we work out a better story telling and motivate at the beginning the plan and scope of the notebook (I think Claude Code can be suer helpful for this as the code is nicely written)

Copy link
Collaborator

@juanitorduz juanitorduz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo


### Fundamentals

::::{grid} 1 2 3 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to modify this? The PR preview looks weird

Image

Copy link
Collaborator

@juanitorduz juanitorduz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some rendering issues 🤔


## Marketing Mix Models (MMM)

### Fundamentals
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we do not put in into Fundamental but in a new "Custom Models" section (with the ../notebooks/mmm/mmm_components.html as well?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but that section should be for custom models with our modularity, I added but move custom models. Instead this notebook use the capabilities in the API MMM, we are never doing a custom pymc model with the building blocks, we are integrating blocks or stuff into the main API and that should be in the fundamentals (people learn our API).

Happy to move it to the new section, but thats my take!

Copy link
Collaborator

@juanitorduz juanitorduz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea

@juanitorduz juanitorduz added this to the 0.17.0 milestone Oct 8, 2025
Copy link
Contributor Author

Added above in the data generation process title.


View entire conversation on ReviewNB

Copy link
Contributor Author

Done!


View entire conversation on ReviewNB

Copy link
Contributor Author

Done!


View entire conversation on ReviewNB

Copy link
Contributor Author

Done!


View entire conversation on ReviewNB

@williambdean
Copy link
Contributor

Maybe reference this in the https://www.pymc-marketing.io/en/latest/notebooks/mmm/mmm_components.html notebook. Maybe at the top

@daniel-saunders-phil
Copy link
Contributor

daniel-saunders-phil commented Oct 8, 2025

Two suggestions:

  1. I wouldn't use the GAM language to describe this notebook. People would expect this to be a tutorial on adding non-parametric functions (especially splines). Wrapping effects up in a non-linear function like exp doesn't qualify it as a GAM as far as I can tell from consulting wikipedia and claude. Maybe some non-technical title like "Add anything to your MMM" would be appropriate because the goal is to provide a general recipe that lets power users do anything they cannot find pre-built in the docs.

  2. We'd want some cleaner division of labour between the existing mmm_components notebook and this one. If I knew I wanted some special customization and saw both of these in the gallery, I wouldn't know which notebook to look at.

What do we think about retitling and refocusing the current components notebook to be "How to model seasonality and special events." @williambdean?

@cetagostini
Copy link
Contributor Author

cetagostini commented Oct 8, 2025

  1. I wouldn't use the GAM language to describe this notebook. People would expect this to be a tutorial on adding non-parametric functions (especially splines). Wrapping effects up in a non-linear function like exp doesn't qualify it as a GAM as far as I can tell from consulting wikipedia and claude. Maybe some non-technical title like "Add anything to your MMM" would be appropriate because the goal is to provide a general recipe that lets power users do anything they cannot find pre-built in the docs.

@daniel-saunders-phil agree with second point, regarding the first not fully sure. Because, as I see it MMM can indeed be viewed as a subclass or applied form of a GAM. My view is this:

  1. Every MMM is a GAM > ❌ Not necessarily (if fully parametric)
  2. A flexible MMM can be implemented as a GAM > ✅ Absolutely — This is the advantageous point of our class.

If you want spine lines, thats definitely possible to implement. I could create customization to implement both saturation and adstock non-parametrically, I'm not saying I'll do it, but if someone does it (and our model can implemented) then why this could not be consider a GAM?

Probably adding this as comment could be enough, no? Will show the point and close the main idea.
ps: This was my idea to bring the notebook to existence, nevertheless, I can be wrong! jeje

@cetagostini
Copy link
Contributor Author

@juanitorduz render checks done. But the error in the test looks unrelated.

@juanitorduz
Copy link
Collaborator

@carlosagostini According to Copilot:

The job failed because the GitHub Actions runner was terminated before all tests finished, as indicated by the error: "The runner has received a shutdown signal... The operation was canceled." This is not a code failure, but an infrastructure/runtime issue. The logs also show warnings about leaked semaphore, semlock, and folder objects, which are common when jobs are forcefully stopped.

Solution:

  1. Re-run the job: This type of failure is usually transient. Use the "Re-run jobs" button in GitHub Actions to try again.
  2. If you frequently see runner shutdowns:
    Check for timeouts in your workflow definition (.github/workflows/test_notebook.yml). Increase timeout limits if necessary (e.g., add or update timeout-minutes: for your steps/jobs).

Ensure the notebooks (like mmm_components.ipynb and mmm_time_slice_cross_validation.ipynb) do not run overly long or consume excessive resources. Optimize their code if possible.

Can you try solution 2, adding the timeout-minutes: parameter ?

@juanitorduz
Copy link
Collaborator

Maybe reference this in the https://www.pymc-marketing.io/en/latest/notebooks/mmm/mmm_components.html notebook. Maybe at the top

Was this reference added?

@juanitorduz
Copy link
Collaborator

@cetagostini , Copilot suggests we modify the runner.py script
If you use joblib.Parallel, modify usage as follows:

from joblib import Parallel, delayed

results = Parallel(n_jobs=4)(delayed(my_func)(i) for i in range(10))
del results
import gc
gc.collect()

maybe worth a try?

@daniel-saunders-phil
Copy link
Contributor

but if someone does it (and our model can implemented) then why this could not be consider a GAM?

It's just misleading to label the notebook as being about GAMs if it only presents linear and non-linear regressions. As a reader, I would expect at least one GAM in the GAM notebook.

@juanitorduz
Copy link
Collaborator

but if someone does it (and our model can implemented) then why this could not be consider a GAM?

It's just misleading to label the notebook as being about GAMs if it only presents linear and non-linear regressions. As a reader, I would expect at least one GAM in the GAM notebook.

This is a fair point @daniel-saunders-phil . I also imagine we are targeting MMM practitioners, so instead of GAMS we could have something more explicit like MMM with custom additive components (or something along those lines but more sexy XD)

@juanitorduz
Copy link
Collaborator

@cetagostini maybe this can help #1986

@cetagostini
Copy link
Contributor Author

@daniel-saunders-phil really agree with you, we should not say GAMs without one!

I build a non parametric form for Saturation and Adstock, as consequence the model with trend, season, and non parametric trasnformations can be considered a GAM. So, this precisely show the point about how to jump from linear models, traditional MMMs, semi-parametric GAM models to fully MMM-GAMs like models.

What do we think? @juanitorduz

@cetagostini cetagostini self-assigned this Oct 9, 2025
@daniel-saunders-phil
Copy link
Contributor

How do you leave in-text comments a PR on the notebook reader website thing? I can see the new GAM content but it won't let me comment on it.

regardless, it looked good to me. Only a typo "our Generative Additive Media Mix Model is alive and sampling" -> "our Generalized Additive Media Mix Model is alive and sampling"

@juanitorduz
Copy link
Collaborator

Could it be that the new notebooks do some really heavy computations? I would not know where

image

@PabloRoque
Copy link
Contributor

I would be careful here.

A user may be tempted to think that they can call optimize on top of whatever custom MMM they define, and this is not the case.

@cetagostini
Copy link
Contributor Author

cetagostini commented Oct 10, 2025

I would be careful here.

A user may be tempted to think that they can call optimize on top of whatever custom MMM they define, and this is not the case.

What do you mean? If they follow the wrapper, they could do. What are cases where that's not true? 🤔 @PabloRoque

@cetagostini
Copy link
Contributor Author

@juanitorduz found issue. The approximate fit method (advi) for large models was taking 2 minutes, I take it out and keep example but only with the simple model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation MMM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants